<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <script type="module">

        import { MyPerson, MyStudent } from "./ES6Singleton.js"

        let myPerson1 = MyPerson.getInstance();
        let myPerson2 = MyPerson.getInstance();
        console.log(myPerson1 === myPerson2);

        let myStudent1 = new MyStudent();
        let myStudent2 = new MyStudent();
        console.log(myStudent1 === myStudent2);


        // 通过代理，单例模式
        class Cat { };
        const createSingleCat = (() => {
            let instance
            return () => {
                if (!instance) {
                    instance = new Cat()
                }
                return instance
            }
        })();

        const a = createSingleCat;
        const b = createSingleCat;
        console.log(a === b)

    </script>
</head>

<body>

</body>

</html>